{*
* 2007-2012 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
*  @author PrestaShop SA <contact@prestashop.com>
*  @copyright  2007-2012 PrestaShop SA
*  @version  Release: $Revision: 14430 $
*  @license    http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
*  International Registered Trademark & Property of PrestaShop SA
*}

{if $opc}
	{assign var="back_order_page" value="order-opc.php"}
{else}
	{assign var="back_order_page" value="order.php"}
{/if}

{*
** Retro compatibility for PrestaShop version < 1.4.2.5 with a recent theme
** Syntax smarty for v2
*}

{* Will be deleted for 1.5 version and more *}
{if !isset($formatedAddressFieldsValuesList)}
	{$ignoreList.0 = "id_address"}
	{$ignoreList.1 = "id_country"}
	{$ignoreList.2 = "id_state"}
	{$ignoreList.3 = "id_customer"}
	{$ignoreList.4 = "id_manufacturer"}
	{$ignoreList.5 = "id_supplier"}
	{$ignoreList.6 = "date_add"}
	{$ignoreList.7 = "date_upd"}
	{$ignoreList.8 = "active"}
	{$ignoreList.9 = "deleted"}	
	
	{* PrestaShop 1.4.0.17 compatibility *}
	{if isset($addresses)}
		{foreach from=$addresses key=k item=address}
			{counter start=0 skip=1 assign=address_key_number}
			{$id_address = $address.id_address}
			{foreach from=$address key=address_key item=address_content}
				{if !in_array($address_key, $ignoreList)}
					{$formatedAddressFieldsValuesList.$id_address.ordered_fields.$address_key_number = $address_key}
					{$formatedAddressFieldsValuesList.$id_address.formated_fields_values.$address_key = $address_content}
					{counter}
				{/if}
			{/foreach}
		{/foreach}
	{/if}
{/if}

<script type="text/javascript">
// <![CDATA[
	{if !$opc}
	var orderProcess = 'order';
	var currencySign = '{$currencySign|html_entity_decode:2:"UTF-8"}';
	var currencyRate = '{$currencyRate|floatval}';
	var currencyFormat = '{$currencyFormat|intval}';
	var currencyBlank = '{$currencyBlank|intval}';
	var txtProduct = "{l s='product'}";
	var txtProducts = "{l s='products'}";
	{/if}

	var formatedAddressFieldsValuesList = new Array();

	{foreach from=$formatedAddressFieldsValuesList key=id_address item=type}
		formatedAddressFieldsValuesList[{$id_address}] =
		{ldelim}
			'ordered_fields':[
				{foreach from=$type.ordered_fields key=num_field item=field_name name=inv_loop}
					{if !$smarty.foreach.inv_loop.first},{/if}"{$field_name}"
				{/foreach}
			],
			'formated_fields_values':{ldelim}
					{foreach from=$type.formated_fields_values key=pattern_name item=field_name name=inv_loop}
						{if !$smarty.foreach.inv_loop.first},{/if}"{$pattern_name}":"{$field_name|escape:'htmlall':'UTF-8'}"
					{/foreach}
				{rdelim}
		{rdelim}
	{/foreach}

	function getAddressesTitles()
	{ldelim}
		return {ldelim}
						'invoice': "{l s='Thông tin hóa đơn'}",
						'delivery': "{l s='Địa chỉ giao hàng'}"
			{rdelim};

	{rdelim}


	function buildAddressBlock(id_address, address_type, dest_comp)
	{ldelim}
		var adr_titles_vals = getAddressesTitles();
		var li_content = formatedAddressFieldsValuesList[id_address]['formated_fields_values'];
		var ordered_fields_name = ['title'];

		ordered_fields_name = ordered_fields_name.concat(formatedAddressFieldsValuesList[id_address]['ordered_fields']);
		ordered_fields_name = ordered_fields_name.concat(['update']);
		
		dest_comp.html('');

		li_content['title'] = adr_titles_vals[address_type];
		li_content['update'] = '<a href="{$link->getPageLink('address.php', true)}?id_address='+id_address+'&amp;back={$back_order_page}?step=1{if $back}&mod={$back}{/if}" title="{l s='Update'}">{l s='Update'}</a>';

		appendAddressList(dest_comp, li_content, ordered_fields_name);
	{rdelim}

	function appendAddressList(dest_comp, values, fields_name)
	{ldelim}
		for (var item in fields_name)
		{ldelim}
			var name = fields_name[item];
			var value = getFieldValue(name, values);
			if (value != "")
			{ldelim}
				var new_li = document.createElement('li');
				new_li.className = 'address_'+ name;
				new_li.innerHTML = getFieldValue(name, values);
				dest_comp.append(new_li);
			{rdelim}
		{rdelim}
	{rdelim}

	function getFieldValue(field_name, values)
	{ldelim}
		var reg=new RegExp("[ ]+", "g");

		var items = field_name.split(reg);
		var vals = new Array();

		for (var field_item in items)
			vals.push(values[items[field_item]]);
		return vals.join(" ");
	{rdelim}

//]]>
</script>

{if !$opc}
	{capture name=path}{l s='Addresses'}{/capture}
	{include file="$tpl_dir./breadcrumb.tpl"}
{/if}

{if !$opc}<h1>{l s='Addresses'}</h1>{else}<h2>1. {l s='Addresses'}</h2>{/if}

{if !$opc}
	{assign var='current_step' value='address'}
	{include file="$tpl_dir./order-steps.tpl"}
	{include file="$tpl_dir./errors.tpl"}


{else}
<div id="opc_account" class="opc-main-block">
	<div id="opc_account-overlay" class="opc-overlay" style="display:none;"></div>
{/if}
 {if $logged}
 <form action="{$link->getPageLink($back_order_page, true)}" method="post">
 {/if}
{* tu *}
	<div class="giao-hang-1">
		<div class="block-1">
			<h2>Các chi nhánh cửa hàng</h2>
				{foreach from=$store item=stores}
					<div class="store">
						<h3>{$stores.name}</h3>
						<p class="address-1">
							{$stores.address1}
						</p>
						<p class="phone">{$stores.phone}</p>
						<p class="checkbox-store">
						</p>
					</div>
				{/foreach}
				
		</div>
                <!--star block2-->
		<div class="block-2">
                    {if !$logged}
                        <form action="{$link->getPageLink('order.php?step=1', true)}" method="post" id="login_form" class="std">
						
							<h3>{l s='Bạn đã đăng kí rồi'}</h3>
							<p class="text">
								<label for="email">{l s='E-mail address'}</label>
								<span><input type="text" id="email" name="email" value="{if isset($smarty.post.email)}{$smarty.post.email|escape:'htmlall':'UTF-8'|stripslashes}{/if}" class="account_input" /></span>
							</p>
							<p class="text">
								<label for="passwd">{l s='Password'}</label>
								<span><input type="password" id="passwd" name="passwd" value="{if isset($smarty.post.passwd)}{$smarty.post.passwd|escape:'htmlall':'UTF-8'|stripslashes}{/if}" class="account_input" /></span>
							</p>
							<p class="submit">
								{if isset($back)}<input type="hidden" class="hidden" name="back" value="{$back|escape:'htmlall':'UTF-8'}" />{/if}
								<input type="submit" id="SubmitLogin" name="SubmitLogin" class="button" value="{l s='Log in'}" />
							</p>
                                                        
				<p class="text-ad1">Cần tiết kiệm thời gian và thêm nhiều ưu đãi, hãy ... đăng ký.</p>		
                        </form>
		<form action="{$link->getPageLink('order.php?step=1', true)}" method="post" id="new_account_form" class="std">
			
				<h3>{l s='Giao hàng không cần đăng kí'}</h3>
				<div id="opc_account_form" style="display: block; ">
					<!-- Account -->
					<p class="required text">
						<label for="guest_email">{l s='E-mail address'}</label>
						<input type="text" class="text" id="guest_email" name="guest_email" value="{if isset($smarty.post.guest_email)}{$smarty.post.guest_email}{/if}">
						<sup>*</sup>
					</p>
					
					<p class="required text">
						<label for="firstname">{l s='Tên Người nhận hàng'}</label>
						<input type="text" class="text" id="firstname" name="firstname" onblur="$('#customer_firstname').val($(this).val());" value="{if isset($smarty.post.firstname)}{$smarty.post.firstname}{/if}">
						<input type="hidden" class="text" id="customer_firstname" name="customer_firstname" value="{if isset($smarty.post.firstname)}{$smarty.post.firstname}{/if}">
						<sup>*</sup>
					</p>
					{if isset($newsletter) && $newsletter}
						<p class="checkbox">
							<input type="checkbox" name="newsletter" id="newsletter" value="1" {if isset($smarty.post.newsletter) && $smarty.post.newsletter == '1'}checked="checked"{/if}>
							<label for="newsletter">{l s='Sign up for our newsletter'}</label>
						</p>
						<p class="checkbox">
							<input type="checkbox" name="optin" id="optin" value="1" {if isset($smarty.post.optin) && $smarty.post.optin == '1'}checked="checked"{/if}>
							<label for="optin">{l s='Receive special offers from our partners'}</label>
						</p>
					{/if}
                                        <p class="text">
							<label for="phone">{l s='Số điện thoại di động'}</label>
							<input type="text" class="text" name="phone" id="phone" value="{if isset($smarty.post.phone)}{$smarty.post.phone}{/if}"> <sup style="color:red;">*</sup>
					</p>
					<p class="required text">
						<label for="address1">{l s='Address'}</label>
                                                <textarea name="address1" id="address1">{if isset($smarty.post.address1)}{$smarty.post.address1}{/if}</textarea>
						<sup>*</sup>
					</p>
                  
						
					<input type="hidden" name="alias" id="alias" value="{l s='My address'}">
					<input type="hidden" name="is_new_customer" id="is_new_customer" value="0">
					<!-- END Account -->
				</div>
			
			<p class="cart_navigation required submit">
				<span><sup>*</sup>Required field</span>
				<input type="submit" class="button" name="submitGuestAccount" id="submitGuestAccount" style="float:right" value="{l s='Đăng kí'}">
			</p>
		</form>
           {else}
               
                    <!--start addresses -->
                    <div class="addresses">
                            <p class="address_delivery select">
                                    <label for="id_address_delivery">{l s='Choose a delivery address:'}</label>
                                    <select name="id_address_delivery" id="id_address_delivery" class="address_select" onchange="updateAddressesDisplay();{if $opc}updateAddressSelection();{/if}">

                                        {foreach from=$addresses key=k item=address}
                                                <option value="{$address.id_address|intval}" {if $address.id_address == $cart->id_address_delivery}selected="selected"{/if}>{$address.alias|escape:'htmlall':'UTF-8'}</option>
                                        {/foreach}

                                    </select>
                            </p>
                            <p class="checkbox" {if $cart->isVirtualCart()}style="display:none;"{/if}>
                                    <input type="checkbox" name="same" id="addressesAreEquals" value="1" onclick="updateAddressesDisplay();{if $opc}updateAddressSelection();{/if}" {if $cart->id_address_invoice == $cart->id_address_delivery || $addresses|@count == 1}checked="checked"{/if} />
                                    <label for="addressesAreEquals">{l s='Use the same address for billing.'}</label>
                            </p>

                            <p id="address_invoice_form" class="select" {if $cart->id_address_invoice == $cart->id_address_delivery}style="display: none;"{/if}>

                            {if $addresses|@count > 1}
                                    <label for="id_address_invoice" class="strong">{l s='Choose a billing address:'}</label>
                                    <select name="id_address_invoice" id="id_address_invoice" class="address_select" onchange="updateAddressesDisplay();{if $opc}updateAddressSelection();{/if}">
                                    {section loop=$addresses step=-1 name=address}
                                            <option value="{$addresses[address].id_address|intval}" {if $addresses[address].id_address == $cart->id_address_invoice && $cart->id_address_delivery != $cart->id_address_invoice}selected="selected"{/if}>{$addresses[address].alias|escape:'htmlall':'UTF-8'}</option>
                                    {/section}
                                    </select>
                                    {else}
                                            <a style="margin-left: 221px;" href="{$link->getPageLink('address.php', true)}?back={$back_order_page}?step=1&select_address=1{if $back}&mod={$back}{/if}" title="{l s='Add'}" class="button_large">{l s='Add a new address'}</a>
                                    {/if}
                            </p>
                            <div class="clear"></div>
                            <ul class="address item" id="address_delivery" {if $cart->isVirtualCart()}style="display:none;"{/if}>
                                
                            </ul>
                            <ul class="address alternate_item {if $cart->isVirtualCart()}full_width{/if}" id="address_invoice">
                            </ul>
                            <br class="clear" />
                            <p class="address_add submit">
                                    <a href="{$link->getPageLink('address.php', true)}?back={$back_order_page}?step=1{if $back}&mod={$back}{/if}" title="{l s='Add'}" class="button_large">{l s='Add a new address'}</a>
                            </p>
                            {if !$opc}
                                <div id="ordermsg">
                                        <p>{l s='Ghi chú khác cho NV giao hàng (không bắt buộc).'}</p>
                                        <p class="textarea"><textarea cols="60" rows="3" name="message">{if isset($oldMessage)}{$oldMessage}{/if}</textarea></p>
                                </div>
                            {/if}
                    </div>
                   <!--end addresses -->
           {/if}
	</div>
                        <!-- end block-2 -->
	</div>
<div class="choose-time" style="clear: both;">
  <h4>Thời gian giao hàng</h4>
  <p>
		<label>Chọn ngày giao hàng</label>
		<input type="text" id="from" name="from">
  </p>
  <div class="list-time">
    <p>Chọn thời điểm giao hàng</p>
    <div class="list">
      	<div class="thoigian_wapper">
				<ul>
					<li class="hour_10">
						<span class="time">10:00am</span>
						<span class="chosse_time">Chọn</span>
						<input type="radio" name="choose_time" value="1">
					</li>
					<li class="hour_11">
						<span class="time">11:00am</span>
						<span class="chosse_time">Chọn</span>
						<input type="radio" name="choose_time" value="2">
					</li>
					<li class="hour_12">
						<span class="time">12:00pm</span>
						<span class="chosse_time">Chọn</span>
						<input type="radio" name="choose_time" value="3">
					</li>
					<li class="hour_13">
						<span class="time">1:00pm</span>
						<span class="chosse_time">Chọn</span>
						<input type="radio" name="choose_time" value="4">
					</li>
					<li class="hour_14">
						<span class="time">2:00pm</span>
						<span class="chosse_time">Chọn</span>
						<input type="radio" name="choose_time" value="5">
					</li>
					<li class="hour_15">
						<span class="time">3:00pm</span>
						<span class="chosse_time">Chọn</span>
						<input type="radio" name="choose_time" value="6">
					</li>
					<li class="hour_16">
						<span class="time">4:00pm</span>
						<span class="chosse_time">Chọn</span>
						<input type="radio" name="choose_time" value="7">
					</li>
					<li class="hour_17">
						<span class="time">5:00pm</span>
						<span class="chosse_time">Chọn</span>
						<input type="radio" name="choose_time" value="8">
					</li>
					<li class="hour_18">
						<span class="time">6:00pm</span>
						<span class="chosse_time">Chọn</span>
						<input type="radio" name="choose_time" value="9">
					</li>
					<li class="hour_20">
						<span class="time">7:00pm</span>
						<span class="chosse_time">Chọn</span>
						<input type="radio" name="choose_time" value="10">
					</li>
					<li class="hour_20">
						<span class="time">8:00pm</span>
						<input type="radio" name="choose_time" value="10">
					</li>
				</ul>
			</div>
    </div>
  </div>
</div>
<div class="time-giao-hang">
      <p class="warming-delivery">
            {l s='Lưu ý khi chọn thời điểm giao hàng'}
      </p>
      <ul>
          <li><p>. Vì lý do giao thông, bạn nên tránh những giờ cao điểm, nó có thể ảnh hưởng đến kế hoạch của bạn.</p></li>
          <li><p>. Chúng tôi khuyến nghị bạn nên chọn những thời điểm ngoài giờ cao điểm (17:00pm-19:00pm), nếu không thể nhận hàng tại nhà, 
  chúng tôi có thể giao hàng cho bạn tại cơ quan bằng cách bạn chọn địa điểm giao hàng khác bằng cách bấm VÀO ĐÂY</p></li>
          <li><p>. Vì năng lực giớ hạn hiện tại chúng tôi chỉ có thể giao hàng tại các quận/huyện:</p></li>
      </ul>
</div>
{* end Tu *}

{if !$opc && $logged}
	<p class="cart_navigation submit">
		<input type="hidden" class="hidden" name="step" value="3" />
		<input type="hidden" name="back" value="{$back}" />
		<a href="{$link->getPageLink($back_order_page, true)}?step=0{if $back}&back={$back}{/if}" title="{l s='Previous'}" class="button">&laquo; {l s='Previous'}</a>
		<input type="submit" name="processAddress" value="{l s='Next'} &raquo;" class="exclusive" />
	</p>
  
{else}
</div>
{/if}
{literal}
	<script>
		jQuery(document).ready(function(){
			var d = new Date();
			var curenttime = (d.getHours()*60*60)+(d.getMinutes()*60)+(d.getSeconds());
			
			var dateToday = addDays(new Date(),0);
			
			if(curenttime+7200 >= 20*3600)/*after 8h pm*/
			{
				console.log('debug');
				var dateToday = addDays(new Date(),1);
			}
			var dates = $("#from").datepicker({
				showOn: "button",
				buttonImage: "{/literal}{$base_dir}{literal}img/calendar.gif",
				buttonImageOnly: true,
				numberOfMonths: 1,
				dateFormat: 'yy-mm-dd',
				minDate: dateToday,
				onSelect: function(selectedDate) {
					var option = this.id == "from" ? "minDate" : "maxDate",
						instance = $(this).data("datepicker"),
						date = $.datepicker.parseDate(instance.settings.dateFormat || $.datepicker._defaults.dateFormat, selectedDate, instance.settings);
						dates.not(this).datepicker("option", option, date);
				}
			})
			function addDays(theDate, days) {
				return new Date(theDate.getTime() + days*24*60*60*1000);
			}
			var curenttime1 = (d.getHours()*60*60)+(d.getMinutes()*60)+(d.getSeconds())+7200;
			console.log(d.getHours()+" "+d.getMinutes()+" "+d.getSeconds())
			
			console.log("current time"+curenttime1);
			jQuery(".thoigian_wapper ul li").each(function(){
			   var time=  $(this).attr('class').replace('hour_','');
			   console.log("list-time"+time*3600);
			   if((time*60*60) < curenttime1 && curenttime1 < 20*3600)
			   {
				   $(this).addClass("block_time");
				   $(this).find("input[name='choose_time']").attr("disabled","disabled")
			   }
			})
			jQuery(".thoigian_wapper ul li").click(function(){
				if(!jQuery(this).hasClass('block_time'))
				{
					jQuery(".thoigian_wapper ul li").find("input[name='choose_time']").attr("checked","");
					jQuery(".thoigian_wapper ul li").removeClass('active_time');
					jQuery(this).addClass("active_time");
					jQuery(this).find("input[name='choose_time']").attr("checked","checked")
				}
			})
		});
	</script>
{/literal}